package com.jk.smartelderlycare.rabbitmq;

import com.jk.smartelderlycare.dto.SysUser;
import com.jk.smartelderlycare.entity.TbOrder;

import com.jk.smartelderlycare.service.TbOrderService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;

import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;


/**
 * @author hhk
 * @version 1.0
 * @ClassName HelloReceiver
 * @program: smart-elderly-care
 * @description: TODO
 * @date 2024/11/28 14:47
 */
@Component
public class HelloReceiver {

    @RabbitListener(queues = "hello")
    public void process(String context) {
        System.out.println("接收到的消息为  : " + context);
    }
    @RabbitListener(queues = "object")
    public void processObj(SysUser sysUser) {
        System.out.println("接收到的消息为  : " + sysUser.toString());
    }
    @RabbitListener(queues = "topic.message")
    public void processMessage(SysUser sysUser) {
        System.out.println("接收到的消息为 exchange,topic.message : " + sysUser.toString());
    }

    @RabbitListener(queues = "topic.messages")
    public void processMessages(SysUser sysUser , @Headers Map<String,Object> header, Channel channel) throws IOException {
        System.out.println("接收到的消息为 fanoutExchange ,topic.messages : " + sysUser.toString());
        //设置手动应答
        Long deliveryTag = (Long) header.get(AmqpHeaders.DELIVERY_TAG);
        //手动签收
        channel.basicAck(deliveryTag,  false);

    }

    @RabbitListener(queues = "fanout.A")
    public void processMessagesA(SysUser sysUser) {
        System.out.println("接收到的消息为 fanoutExchange,fanout.A : " + sysUser.toString());
    }

    @RabbitListener(queues = "fanout.B")
    public void processMessagesB(SysUser sysUser) {
        System.out.println("接收到的消息为 fanoutExchange,fanout.B : " + sysUser.toString());
    }

    @RabbitListener(queues = "fanout.C")
    public void processMessagesC(SysUser sysUser) {
        System.out.println("接收到的消息为 fanoutExchange,fanout.C: " + sysUser.toString());
    }





}
